<template>
  <div>
    <van-nav-bar
      title="设置昵称"
      left-text="返回"
      right-text="确定"
      @click-left="$emit('close')"
      @click-right="onClickRight"
    />
    <van-field
      v-model.trim="message"
      rows="2"
      autosize
      type="textarea"
      maxlength="7"
      placeholder="请输入昵称"
      show-word-limit
    />
  </div>
</template>

<script>
import { updateUserName } from '../../../api/user'
export default {
  name: 'HeimaiUpdateName',

  data() {
    return {
      message: this.value
    };
  },
  props: {
    value: {
      type: String,
      require: true
    }
  },
  mounted() {

  },

  methods: {
    async onClickRight() {
      if (!this.message) {
        return this.$toast('昵称不能为空！')
      }
      try {
        await updateUserName({
          name: this.message
        })
        this.$emit('close')
        this.$emit('input', this.message)
      } catch (error) {
        this.$toast('修改失败！')
      }
    }
  }
};
</script>

<style lang="less" scoped>
</style>